<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>编辑单位信息</title>
</head>
<body>
<div id="editCompanyForm">
        <div class="form-Container">
            <form action="${pageContext.request.contextPath}/company/editCompany.do"  id="dataForm" class="grayForm" method="post">
                <input type="hidden" name="id" value="${param.id }"/>
                <input type="hidden" name="parentName" id="parentName" value="${param.parentName }"/>
                <input type="hidden" name="uuid" id="uuid" value=""/>
                <table>
                    <tr>
                        <td><label for="parentName">上级单位:</label></td>
                        <td colspan="3" style="line-height:20px;">
                          <input type="text" class="easyui-combotree" id="parentUUID" name="parentUUID" value="${param.parentUUID }"
	                           data-options="
	                                prompt:'请选择',
	                                width:462,
	                                height:25,
	                                panelHeight:300,
	                                url:'<%=basePath %>company/getCompanyList4Tree.do',    
					        	    valueField:'id',
					        	    textField:'text',
					        	    onSelect:function(node){
					        	       $('#parentName').val(node.text);
								    }
					        	    "/><br/>
					        	    <span id="parentUUIDMsg" style="color:red;font-weight:bold"></span>
                        </td>
                    </tr>
                    <tr>
                        <td><label for="companyName">单位名字:</label></td>
                        <td colspan="3" style="line-height:20px;"><input type="text" required name="companyName" id="companyName" style="width:462px;"/></td>
                    </tr>
                    <tr>
                        <td ><label for="companyPhone">电话号码:</label></td>
                        <td style="line-height:20px;"><input type="text" id="companyPhone" required name="companyPhone"  /></td>
                        <td ><label for="companyAuthority">责任人:</label></td>
                        <td style="line-height:20px;"><input type="text" id="companyAuthority" required name="companyAuthority"  /></td>
                    </tr>
                    <tr>
                        <td ><label for="companyIp">IP地址:</label></td>
                        <td style="line-height:20px;"><input type="text" id="companyIp" name="companyIp"  /></td>
                        <td ><label for="companyNet">网址:</label></td>
                        <td style="line-height:20px;"><input type="text" id="companyNet" name="companyNet"  /></td>
                    </tr>
                    <tr>
                        <td ><label for="companyType">单位类型:</label></td>
                        <td style="line-height:20px;">
                          <select name="companyType" id="companyType"  class="select-box" curV="">
                               <option value="私营企业">私营企业</option>
                               <option value="国有企业">国有企业</option>
                           </select>
                        </td>
                        <td ><label for="companyState">单位状态:</label></td>
                        <td style="line-height:20px;">
                          <select name="companyState" id="companyState"  class="select-box" curV="">
                               <option value="1">1.可用</option>
                               <option value="0">0.不可用</option>
                           </select>
                        </td>
                    </tr>
                    <tr>
                        <td><label for="companyAddress">单位地址:</label></td>
                        <td colspan="3" style="line-height:20px;"><input type="text" required name="companyAddress" id="companyAddress" style="width:462px;"/></td>
                    </tr>
                    <tr>
                        <td><label for="orderNumber">排序序号:</label></td>
                        <td colspan="3" style="line-height:20px;"><input type="text" name="orderNumber" id="orderNumber"/></td>
                    </tr>
                    <tr>
                        <td><label for="companyRemark">备注:</label></td>
                        <td colspan="3" style="line-height:20px;"><input type="text" name="companyRemark" id="companyRemark" style="width:462px;"/></td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: center;">
                            <input type="button" value="提交数据" name="submitData"  />
                            <input type="button" value="关闭" name="close" />
                        </td>
                    </tr>
                </table>
                <div id="confirmMsg"></div>
            </form>
        </div>
        <script type="text/javascript">
        $(document).ready(function () {
        	var id = $("#editCompanyForm input[name='id']").val();
        	if(id!=""){
        		//加载表单数据
            	loadFormData(id+"");
        	}
        	var rules = {}
        	var messages = {}
        		messages = {
        			companyName:"请输入单位名字",
        			companyPhone:"请输入单位联系电话",
        			companyAuthority:"请输入单位负责人",
        			companyAddress:"请输入单位地址",
            };
        	
        	var validateForm = $("#editCompanyForm #dataForm").validate({
                debug:true,
                rules:rules,
                messages:messages
            });
        	
        	$("#editCompanyForm input[name='close']").click(function () {
       		    $("#editDataFormArea").window("close");
       	    })
        	
            //提交数据到服务器
            $("#editCompanyForm input[name='submitData']").click(function () {
            	$("#editDataFormArea").panel('resize',{
            		  width:660,
                      height:400
				});
            	//提交表单进行验证
            		$("#editCompanyForm #dataForm").form('submit',{
            			//当提交时
            			onSubmit:function(param){
            				if(!validateForm.form()){
            					return false;
            				}
            			},
            			success:function(data){
            				var data = eval('(' + data + ')');
            				if(data.code=="00"){
              				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？',function(flag){
              					  if(flag){
              						  var parentUUID = $("#dataForm #parentUUID").val();
              						  console.log("parentUUID："+parentUUID);
              						  $("#searchForm input[name='parentUUID']").val(parentUUID);
              						  loadCompanyTree();
              						  seachData();
              						  $("#editDataFormArea").window("close");
              					  }
              				  });
              			    }else{
              				   $.messager.alert('操作提示',data.msg,'error');
              			    }
            			}
            		});
            });
        	
        });
        
        //通过表单加载数据
        function loadFormData(id){
        	$.post(getBasePath()+"/company/getJsonDetail.do",{id:id},function(jsonData){
        		$("#editCompanyForm #dataForm").form("load",jsonData.data);
  		    },"json");
        }
    </script>
 </div>
</body>
</html>